﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using Ace;
using Ace.Application.Common;
using Ace.Application.Wiki;
using Ace.Entity.Wiki;
using Ace.IdStrategy;
using Ace.Web.Mvc;
using Ace.Web.Mvc.Authorization;
using Ace.Web.Mvc.Models;
using Chloe.Admin.Common;
using Chloe.Admin.Common.Tree;
using Microsoft.AspNetCore.Mvc;

namespace Chloe.Admin.Areas.Wiki.Controllers
{

    [Area(AreaNames.Wiki)]
    [Permission("wiki.userscharge")]
    public class UsersChargeController : WebController<IUsersChargeService>
    {
        public IActionResult Index()
        {
            List<UsersChargeItem> list = this.CreateService<IUsersChargeItemService>().GetList();
            ViewBag.ChargeItemList = list;

            return View();
        }

        public ActionResult Models(Pagination pagination,int ChargeSort=-2, string keyword="")
        { 
            PagedData<UsersChargeInfo> pagedData = this.Service.GetPageList(pagination, ChargeSort, keyword,"","","");
            return this.SuccessData(pagedData);
        }


        [Permission("wiki.userscharge.delete")]
        [HttpPost]
        public ActionResult Delete(string id)
        { 
            this.Service.Delete(id);
            return this.SuccessMsg("删除成功");
        }
         
 


        [Permission("wiki.userscharge.edit")]
        [HttpPost]
        public ActionResult Edit(UpdateUsersChargeInput modle)
        {
            modle.CreateID = this.CurrentSession.UserId;
            this.Service.Update(modle);
            return this.SuccessMsg("编辑成功");
        }

        [Permission("wiki.userscharge.add")]
        [HttpPost]
        public ActionResult Add(AddUsersChargeInput modle)
        {
            

            modle.ChargeCode = "WH" + DateTime.Now.ToString("yyyyMMddHHmmssfff");
            modle.CreateID = this.CurrentSession.UserId;
            modle.CreateDate = DateTime.Now;
            modle.Balance = 0;
            if(modle.ChargeSort==0)
            {
                modle.Title = "消费";
            }
            else
            {
                modle.Title = "充值";
            }
            this.Service.Add(modle);
            return this.SuccessMsg("添加成功");
        }


        public ActionResult GetModelByMobile(string Mobile)
        {
            Users users = this.CreateService<IUsersService>().GetModelByMobile(Mobile);
            if(users!=null)
            {
                return this.SuccessData(users);
            }
            else
            {
                return this.FailedMsg("没有查询到用户信息");
            }
        }

    }
}